home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Reminder Manager / About.c next >
C/C++ Source or Header  |  1995-06-24  |  2KB  |  100 lines

  1. #include "About.h"
  2.  
  3. //#define      TRUE   1
  4. //#define      FALSE  0
  5. #define      NIL    0
  6. #define         ABOUT  67
  7.  
  8. static WindowPtr    MyWindow;
  9. static Rect            picRect;
  10. static int            canAbout = TRUE;
  11.  
  12.  
  13. void  Init_About()
  14. {
  15.     MyWindow = NIL;
  16. }
  17.  
  18. void  Close_About()
  19. {
  20.     if (MyWindow!=NIL) {
  21.         DisposeWindow(MyWindow); 
  22.         MyWindow = NIL;
  23.     }
  24.  
  25. void  Update_About()
  26. {
  27. WindowPtr   SavePort;
  28. PicHandle   Pic_Handle;
  29. Rect        tempRect;
  30. SignedByte    huhstate;
  31.     
  32.     if (MyWindow!=NIL && canAbout)
  33.     {
  34.         GetPort(&SavePort);
  35.         SetPort(MyWindow);
  36.  
  37.         Pic_Handle = GetPicture(ABOUT);
  38.         if (Pic_Handle != NIL) 
  39.         {
  40.             huhstate = HGetState((Handle)Pic_Handle);
  41.             MoveHHi((Handle)Pic_Handle);
  42.             HLock((Handle)Pic_Handle);
  43.             DrawPicture(Pic_Handle,&picRect);
  44.             HSetState((Handle)Pic_Handle,huhstate);
  45.         }
  46.         else {
  47.             canAbout = FALSE;
  48.             Close_About();
  49.         };
  50.         SetPort(SavePort);
  51.     }
  52. }
  53.  
  54. void Open_About()
  55. {
  56. PicHandle    Pic_Handle;
  57. int        v,h;
  58.  
  59.     // I have since seen much simpler code for doing this,
  60.     // but I am keeping this stuff for hysterical raisins
  61.     if (MyWindow == NIL && canAbout) 
  62.     {
  63.         /*     1. Load the picture */
  64.         Pic_Handle = GetPicture(ABOUT);
  65.         if (Pic_Handle != NIL) {                
  66.             HLock((Handle)Pic_Handle);            
  67.             /*    2. Compute the size and clipping rect */
  68.             picRect.top = 0;
  69.             picRect.left = 0;
  70.             picRect.right = (*Pic_Handle)->picFrame.right 
  71.                             - (*Pic_Handle)->picFrame.left;
  72.             picRect.bottom = (*Pic_Handle)->picFrame.bottom 
  73.                             - (*Pic_Handle)->picFrame.top;        
  74.             HUnlock((Handle)Pic_Handle);
  75.         };
  76.         
  77.         /*    3. Load the window */
  78.         MyWindow = GetNewWindow(2,NIL, (WindowPtr)-1);
  79.         SetPort(MyWindow);
  80.         
  81.         /*    4. resize the window slightly bigger than the PICT */
  82.         HLock((Handle)MyWindow);
  83.         SizeWindow(MyWindow,picRect.right,picRect.bottom,TRUE);
  84.         
  85.         /*    5. Position the window top third center */
  86.         v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) 
  87.             - (MyWindow->portRect.bottom - MyWindow->portRect.top)) / 3;
  88.         h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) 
  89.             - (MyWindow->portRect.right - MyWindow->portRect.left)) / 2;
  90.         MoveWindow(MyWindow,h,v,TRUE);
  91.         HUnlock((Handle)MyWindow);
  92.         
  93.         /*    6. Show the window */        
  94.         ShowWindow(MyWindow);
  95.     }
  96.         if (MyWindow!=NIL)
  97.             SelectWindow(MyWindow);
  98. }
  99.